import static org.junit.Assert.*;

import java.math.BigDecimal;
import java.util.Vector;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.*;

public class BankTest {

	Bank testBank;
	Customer testCustomer;
	
	@Before
	public void setUp() throws Exception {
		testBank = new Bank("test bank");
		testCustomer = new Customer("test first name", "test last name", "test street", "test zip", "test town", "test country");
	}

	@After
	public void tearDown() throws Exception {
		testBank = null;
		testCustomer = null;
	}

	@Test
	public void testBank() {
		assertEquals(testBank.name, "test bank");
		assertTrue(testBank.checkingAccounts instanceof Vector);
		assertTrue(testBank.savingAccounts instanceof Vector);
	}

	@Test
	public void testOpenCheckingAccount() {
		int accountNumber = testBank.openCheckingAccount(testCustomer);
		assertEquals(accountNumber, testBank.checkingAccounts.firstElement().accountNumber);
	}

	@Test
	public void testOpenSavingsAccount() {
		int accountNumber = testBank.openSavingsAccount(testCustomer);
		assertEquals(accountNumber, testBank.savingAccounts.firstElement().accountNumber);		
	}
	
	@Test
	public void testOpenFullPackage() {
		int accountNumber = testBank.openFullPackage(testCustomer);
		CheckingAccount firstCheck = testBank.checkingAccounts.firstElement();
		assertEquals(accountNumber, firstCheck.accountNumber);
//		assertNotNull(firstCheck.fCreditCard);
		SavingsAccount firstSave = testBank.savingAccounts.firstElement();
		assertNotNull(firstSave);
	}

	@Test
	public void testWithdrawMoney() {
		int accountNumber = testBank.openCheckingAccount(testCustomer);
		CheckingAccount dummyCheck = new CheckingAccount(accountNumber);
		int acctIndex = testBank.checkingAccounts.indexOf(dummyCheck);
		testBank.checkingAccounts.get(acctIndex).balance = new BigDecimal(String.valueOf(100.0));
		assertTrue(testBank.withdrawFromChecking(accountNumber, new BigDecimal("10.00")));
	}

}
